home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.10 Oct 90 / NewToolBox.π / NewToolBox.Lib / LWind.Asm < prev    next >
Encoding:
Assembly Source File  |  1989-09-02  |  12.9 KB  |  423 lines  |  [TEXT/KAHL]

  1. ;**************************
  2. ;*     Window Manager     *
  3. ;************************** 
  4.  
  5.  
  6. INCLUDE Library.Txt
  7.  
  8. ;-------------------------------
  9. ; ***   External Definition  ***
  10. ;-------------------------------   
  11.  
  12. XDEF InstalWindow
  13. XDEF DeInstalWindow
  14. XDEF ExecWindow
  15. XDEF GetWindowAuxRec
  16. XDEF GetWindowClip
  17. XDEF SetWindowClip
  18. XDEF SetCurrents
  19. XDEF GetCurrents
  20. XDEF WindowWithGrow
  21.  
  22. ;-------------------------------
  23. ;****   The Window Record   ****
  24. ;-------------------------------
  25.  
  26. ;WindowRecord = Record  {156 bytes}
  27. ;{  0}          port : GrafPort
  28. ;{108}    windowKind : INTEGER
  29. ;{110}       visible : BOOLEAN
  30. ;{111}       hilited : BOOLEAN
  31. ;{112}    goAwayFlag : BOOLEAN
  32. ;{113}     spareFlag : BOOLEAN
  33. ;{114}      strucRgn : RgnHandle
  34. ;{118}       contRgn : RgnHandle
  35. ;{122}     updateRgn : RgnHandle
  36. ;{126} windowDefProc : DEFfunHandle
  37. ;{130}    dataHandle : Handle
  38. ;{134}   titleHandle : StringHandle
  39. ;{138}    titleWidth : INTEGER
  40. ;{140}   ControlList : ControlHandle
  41. ;{144}    nextWindow : WindowPeek
  42. ;{148}     windowPic : PicHandle
  43. ;{152}     WrefCon   : LongInt
  44.  
  45. ;-------------------------------
  46. ;**    The Window AuxRecord   **
  47. ;-------------------------------
  48.  
  49. ;AuxWinRecord = Record {48}
  50. ;{0}    Worigin        : Point     Origin of ClipRgn
  51. ;{4}    WContRect    : Rect      Window's portRect minus scroll bars (if any)
  52. ;{12}    WactivTxt    : TEHandle     Current Active TEdit
  53. ;{16}    WactivLst    : ListHandle    Current Active List
  54. ;{20}    Wgrow        : Boolean    True if window has grow box
  55. ;{22}    WPrintRec    : THPrint    Handle to the Window Print Record    
  56. ;{26}    WindProc    : ProcPtr    Window Procedure
  57. ;{30}    WvRefNum    : Integer    Volume RefNum.
  58. ;{32}    WAuxRefC    : LongInt    the Window WrefCon
  59. ;{36}    WText          : Handle    list of TEHandle
  60. ;{40}   WList          : Handle     list of ListHandle 
  61. ;{44}    WPic        : Handle    list of Pictures
  62.                                            
  63. ; --------------------------------
  64.  
  65.                    
  66.                    
  67. ;------------------------------------------------------------------------------
  68. ;FUNCTION InstalWindow(VAR theWindow:WindowPtr;WindID:INTEGER;
  69. ;               WProc:ProcPtr;hasGrow:BOOLEAN):OSErr;
  70. ;------------------------------------------------------------------------------
  71.  
  72. ;-------------------------------
  73. ; Parameters
  74. ;-------------------------------
  75.  
  76. hasGrow         EQU 8
  77. WProc          EQU 10
  78. WindID          EQU 14
  79. VARtheWindow    EQU 16
  80.  
  81. ;-------------------------------
  82. ; Local Variables
  83. ;-------------------------------
  84.  
  85. theWindow       EQU -4
  86. theRefCon       EQU -8
  87. theHandle       EQU -12
  88. error           EQU -14
  89.  
  90. ;-------------------------------
  91.  
  92. InstalWindow 
  93.     LINK A6,#-14              ;
  94.     MOVEM.L A2-A4/D3-D7,-(SP) ;
  95.     MOVE.W #noErr,error(A6)   ;
  96.     MOVE.L #NIL,theWindow(A6) ;
  97.     MOVE.L #SizeWindRec,D0    ;space for
  98.     _NewPtr                   ;a new window
  99.     MOVE.W D0,error(A6)       ;record.
  100.     BNE @0                    ;if error...    
  101.     MOVE.W WindID(A6),-(SP)   ;    exit.
  102.     MOVE.L A0,-(SP)           ;    
  103.     MOVE.L #-1,-(SP)          ;    
  104.     _GetNewWindow             ;get a window...
  105.     MOVE.L (SP)+,theWindow(A6);from resource
  106.     MOVE.W #nilHandleErr,error(A6);
  107.     CMPI.L #NIL,theWindow(A6) ;can't read ?
  108.     BEQ @0                    ;so, exit.    
  109.     MOVEA.L theWindow(A6),A4  ;    
  110.     MOVE.L WrefCon(A4),theRefCon(A6);    
  111.     MOVE.L #NIL,WrefCon(A4)   ;    
  112.     MOVE.L #SizeAuxWind,D0    ;space for
  113.     _NewHandle                ;AuxWind     
  114.     MOVE.W D0,error(A6)       ;record
  115.     BNE @1                    ;error ?
  116.     MOVEA.L theWindow(A6),A4  ;put new handle
  117.     MOVE.L A0,WrefCon(A4)     ;in WrefCon    
  118.     MOVEA.L (A0),A3           ;initialize...
  119.     MOVE.L #0,Worigin(A3)     ;
  120.     MOVE.L portRect(A4),WContRect(A3)    ;   
  121.     MOVE.L portRect+4(A4),WContRect+4(A3);
  122.     TST.W  hasgrow(A6)        ;
  123.     BEQ @2            ;if window has
  124.     SUB.W #15,WContRect+4(A3)   ;scroll bars
  125.     SUB.W #15,WContRect+6(A3)   ;portRect. -15
  126. @2
  127.     MOVE.W hasgrow(A6),Wgrow(A3);
  128.     MOVE.L #NIL,WactivTxt(A3)   ;
  129.     MOVE.L #NIL,WactivLst(A3)   ;
  130.     MOVE.L WProc(A6),WindProc(A3) ;
  131.     MOVE.L #NIL,WPrintRec(A3)   ;
  132.     MOVE.L #0,WAuxRefC(A3)    ;
  133.     MOVE.W #0,WvRefNum(A3)    ;
  134.     MOVEQ #SizeListAuxRec,D0    ;space for
  135.     _NewHandle                  ;linked list
  136.     MOVE.W D0,error(A6)         ;for list...
  137.     BNE @1                    ;
  138.     MOVEA.L theWindow(A6),A1    ;    
  139.     MOVE.L WrefCon(A1),A1         ;initialize    
  140.     MOVE.L (A1),A3              ;fields
  141.     MOVE.L A0,WList(A3)         ;of list
  142.     MOVEA.L (A0),A3             ;Aux record
  143.     CLR.W LID(A3)               ; 
  144.     MOVE.L #NIL,theList(A3)     ;
  145.     MOVE.L #NIL,nextList(A3)    ;
  146.     CLR.W fontList(A3)          ;
  147.     CLR.W sizList(A3)           ;
  148.     MOVE.W #SizeTEAuxRec,D0     ;and for
  149.     _NewHandle                  ;text
  150.     MOVE.W D0,error(A6)         ;
  151.     BNE @1            ;
  152.     MOVEA.L theWindow(A6),A1    ;    
  153.     MOVE.L WrefCon(A1),A1         ;    
  154.     MOVE.L (A1),A3              ;                               
  155.     MOVE.L A0,WText(A3)         ;initialize
  156.     MOVEA.L (A0),A3             ;fields
  157.     CLR.W TID(A3)                 ;of text 
  158.     MOVE.L #NIL,theText(A3)     ;Aux record
  159.     MOVE.L #NIL,nextText(A3)    ;
  160.     MOVE.W #SizePicAuxRec,D0    ;
  161.     _NewHandle                  ;
  162.     MOVE.W D0,error(A6)         ;and now
  163.     BNE @1                      ;for pictures.
  164.     MOVEA.L theWindow(A6),A1    ;space for    
  165.     MOVE.L WrefCon(A1),A1         ;Pict AuxRec    
  166.     MOVE.L (A1),A3              ;
  167.     MOVE.L A0,WPic(A3)          ;
  168.     MOVEA.L (A0),A3             ; 
  169.     CLR.W PID(A3)            ; 
  170.     MOVE.L #NIL,thePic(A3)      ; 
  171.     MOVE.L #NIL,nextPic(A3)     ; 
  172.     CLR.L destRect(A3)        ;
  173.     CLR.L destRect+4(A3)    ;
  174.     CLR.W tMode(A3)             ;
  175.     BRA @0            ;    
  176. @1
  177.     MOVE.L theWindow(A6),-(SP);sorry,
  178.     _DisposWindow          ;an error occurs.
  179. @0 
  180.     MOVE.W error(A6),D0       ;
  181.     MOVE.L VARtheWindow(A6),A1;
  182.     MOVE.L theWindow(A6),(A1) ;
  183.     MOVEM.L (SP)+,A2-A4/D3-D7 ;
  184.     UNLK A6                   ; 
  185.     MOVE.L (SP)+,A0           ;
  186.     ADD.L #12,SP              ;clean the
  187.     MOVE.W D0,(SP)            ;stack,report
  188.     JMP (A0)                  ;error and quit  
  189.  
  190. ;------------------------------------------------------------------------------
  191. ;PROCEDURE ExecWindow(theEvent:EventRecord;whichWindow:WindowPtr);
  192. ;------------------------------------------------------------------------------ 
  193.  
  194. ;-------------------------------
  195. ; Parameters
  196. ;-------------------------------
  197.  
  198. whichWindow EQU 8
  199. theEvent    EQU 12
  200.  
  201. ;-------------------------------
  202.  
  203. ExecWindow
  204.     LINK A6,#0                 ;
  205.     MOVEM.L A2-A4/D3-D7,-(SP)  ;
  206.     MOVEA.L whichWindow(A6),A4 ;
  207.     TST.L WrefCon(A4)          ;NIL in
  208.     BEQ @0                     ;the Wind
  209.     MOVEA.L WrefCon(A4),A2     ;Aux Record?
  210.     MOVEA.L (A2),A2            ;
  211.     MOVEA.L WindProc(A2),A2    ;get the Wind
  212.     CMPA.L #NIL,A2             ;proc address
  213.     BEQ @0                     ;address is NIL?
  214.     MOVE.L theEvent(A6),-(SP)  ;push eventRec
  215.     MOVE.L whichWindow(A6),-(SP);
  216.     JSR (A2)                   ;run the WindProc
  217. @0 
  218.     MOVEM.L (SP)+,A2-A4/D3-D7  ;
  219.     UNLK A6                    ;
  220.     MOVEA.L (SP)+,A0           ;
  221.     ADD.L #8,SP                ;
  222.     JMP (A0)                   ;
  223.  
  224. ;------------------------------------------------------------------------------
  225. ;FUNCTION GetWindowAuxRec(whichWindow:WindowPtr):Handle;
  226. ;------------------------------------------------------------------------------ 
  227.  
  228. GetWindowAuxRec
  229.     MOVEA.L (SP)+,A0           ;
  230.     MOVEA.L (SP)+,A1           ;
  231.     TST.L WrefCon(A1)          ;
  232.     BEQ @0                     ;
  233.     MOVE.L WrefCon(A1),(SP)    ;
  234. @0
  235.     JMP(A0)                    ;
  236.  
  237.  
  238.     
  239. ;------------------------------------------------------------------------------
  240. ;PROCEDURE GetWindowClip(VAR contentRect:rect;VAR clipOrigin:Point;
  241. ;                        whichWindow:WindowPtr);
  242. ;------------------------------------------------------------------------------ 
  243.  
  244. ;-------------------------------
  245. ; Parameters
  246. ;-------------------------------
  247.  
  248. clipOrigin    EQU 12
  249. contentRect   EQU 16
  250.  
  251. ;-------------------------------
  252.  
  253. GetWindowClip
  254.     LINK A6,#-0                 ;
  255.     MOVEM.L A2-A4/D3-D7,-(SP)   ;
  256.     MOVE.L whichWindow(A6),A4   ;
  257.     TST.L WrefCon(A4)           ;
  258.     BEQ @0                      ;
  259.     MOVEA.L WrefCon(A4),A0      ;
  260.     MOVEA.L (A0),A0             ;
  261.     MOVEA.L clipOrigin(A6),A1   ;
  262.     MOVEA.L contentRect(A6),A2  ;
  263.     MOVE.L Worigin(A0),(A1)     ;
  264.     MOVE.L WContRect(A0),(A2)+  ;
  265.     MOVE.L WContRect+4(A0),(A2) ;
  266. @0
  267.     MOVEM.L (SP)+,A2-A4/D3-D7   ;
  268.     UNLK A6                     ;
  269.     MOVEA.L (SP)+,A0            ;
  270.     ADD.L #12,SP                ;
  271.     JMP (A0)                    ; 
  272.  
  273. ;------------------------------------------------------------------------------
  274. ;PROCEDURE SetWindowClip(contentRect:rect;clipOrigin:Point;
  275. ;                        whichWindow:WindowPtr);
  276. ;------------------------------------------------------------------------------ 
  277.  
  278. SetWindowClip
  279.     LINK A6,#-0                   ;
  280.     MOVEM.L A2-A4/D3-D7,-(SP)     ;
  281.     MOVE.L whichWindow(A6),A4     ;
  282.     TST.L WrefCon(A4)             ;
  283.     BEQ @0                        ;
  284.     MOVEA.L WrefCon(A4),A0        ;
  285.     MOVEA.L (A0),A0               ;
  286.     MOVE.L clipOrigin(A6),Worigin(A0);
  287.     MOVEA.L contentRect(A6),A2    ;
  288.     MOVE.L (A2)+,WContRect(A0)    ;
  289.     MOVE.L (A2),WContRect+4(A0)   ;
  290. @0
  291.     MOVEM.L (SP)+,A2-A4/D3-D7     ;
  292.     UNLK A6                       ;
  293.     MOVEA.L (SP)+,A0              ;
  294.     ADD.L #12,SP                  ;
  295.     JMP (A0)                      ;
  296.     
  297. ;------------------------------------------------------------------------------
  298. ;PROCEDURE SetCurrents(currentText:TEHandle;currentList:ListHandle;
  299. ;               whichWindow:WindowPtr);
  300. ;------------------------------------------------------------------------------ 
  301.  
  302. SetCurrents
  303.     MOVEA.L (SP)+,A0            ;
  304.     MOVEA.L (SP)+,A1            ;
  305.     TST.L WrefCon(A1)           ;
  306.     BEQ @0                      ;
  307.     MOVEA.L WrefCon(A1),A1      ;
  308.     MOVEA.L (A1),A1             ;
  309.     MOVE.L (SP)+,WactivLst(A1)  ;
  310.     MOVE.L (SP)+,WactivTxt(A1)  ;
  311. @0
  312.     JMP (A0)                    ;
  313.  
  314. ;------------------------------------------------------------------------------
  315. ;PROCEDURE GetCurrents(VAR currentText:TEHandle;VAR currentList:ListHandle;
  316. ;               whichWindow:WindowPtr);
  317. ;------------------------------------------------------------------------------           
  318.     
  319. GetCurrents
  320.     MOVEA.L (SP)+,A0         ;
  321.     MOVEA.L (SP)+,A1         ;
  322.     TST.L WrefCon(A1)        ;
  323.     BEQ @0                   ;
  324.     MOVEA.L WrefCon(A1),A1   ;
  325.     MOVEA.L (A1),A1          ;
  326.     MOVE.L (SP)+,A2         ;
  327.     MOVE.L WactivLst(A1),(A2);
  328.     MOVE.L (SP)+,A2         ;
  329.     MOVE.L WactivTxt(A1),(A2);
  330. @0
  331.     JMP (A0)                 ;
  332.  
  333. ;------------------------------------------------------------------------------
  334. ;FUNCTION WindowWithGrow(whichWindow:WindowPtr):BOOLEAN;
  335. ;------------------------------------------------------------------------------ 
  336.  
  337. WindowWithGrow
  338.     MOVEA.L (SP)+,A0                ;
  339.     MOVEA.L (SP)+,A1                ;
  340.     TST.L WrefCon(A1)               ;
  341.     BEQ @0                        ;
  342.     MOVEA.L WrefCon(A1),A1          ;
  343.     MOVEA.L (A1),A1                 ;
  344.     MOVE.W Wgrow(A1),(SP)           ;
  345. @0
  346.     JMP (A0)                        ;
  347.  
  348. ;------------------------------------------------------------------------------
  349. ;PROCEDURE DeInstalWindow(whichWindow:WindowPtr);
  350. ;------------------------------------------------------------------------------ 
  351.  
  352. DeInstalWindow
  353.     LINK A6,#-0                    ;
  354.     MOVEM.L A2-A4/D3-D7,-(SP)      ;
  355.     MOVE.L whichWindow(A6),A4      ;
  356.     TST.L WrefCon(A4)              ;
  357.     BEQ @0                         ;    
  358.     MOVE.L WrefCon(A4),A4          ;we lock
  359.     MOVE.L A4,A0               ;WindAuxRec
  360.     _HLock                   ; A4 will
  361.     MOVE.L (A4),A4        ;point on it
  362. @2
  363.     TST.L WText(A4)        ;
  364.     BEQ @1            ;
  365.     MOVE.L WText(A4),A3        ;
  366.     MOVE.L (A3),A2        ;
  367.     MOVE.L nextText(A2),WText(A4);
  368.     TST.L theText(A2)        ;
  369.     BEQ @6            ;dispose each
  370.     MOVE.L theText(A2),-(SP)    ;text...
  371.     _TEDispose            ;
  372. @6  
  373.     MOVE.L A3,A0        ;...and then
  374.     _DisposHandle        ;the TEAuxRec
  375.     BRA @2            ;
  376. @1 
  377.     TST.L WList(A4)        ;
  378.     BEQ @3            ;
  379.     MOVE.L WList(A4),A3        ;
  380.     MOVE.L (A3),A2        ;
  381.     MOVE.L nextList(A2),WList(A4);
  382.     TST.L theList(A2)        ;
  383.     BEQ @7            ;dispose each
  384.     MOVE.L theList(A2),-(SP)    ;list...
  385.     _LDispose            ;
  386. @7
  387.     MOVE.L A3,A0        ;
  388.     _DisposHandle        ;...and then
  389.     BRA @1            ;the ListAuxRec
  390. @3
  391.     TST.L WPic(A4)        ;
  392.     BEQ @4            ;
  393.     MOVE.L WPic(A4),A3        ;
  394.     MOVE.L (A3),A2        ;
  395.     MOVE.L nextPic(A2),WPic(A4)    ;
  396.     TST.L thePic(A2)        ;
  397.     BEQ @8            ;dispose each
  398.     MOVE.L thePic(A2),-(SP)    ;picture
  399.     _KillPicture        ;
  400. @8
  401.     MOVE.L A3,A0        ;
  402.     _DisposHandle        ;and the
  403.     BRA @3            ;PicAuxRec    
  404. @4   
  405.     TST.L WPrintRec(A4)        ;
  406.     BEQ @5            ;dispose
  407.     MOVE.L WPrintRec(A4),A0    ;the PrintRecord
  408.     _DisposHandle        ;
  409. @5    
  410.     MOVE.L whichWindow(A6),A4   ;
  411.     MOVE.L WrefCon(A4),A4    ;
  412.     MOVE.L A4,A0        ;
  413.     _HUnLock            ;
  414.     MOVE.L whichWindow(A6),-(SP);dispose the 
  415.     _DisposWindow        ;window
  416. @0    
  417.     MOVEM.L (SP)+,A2-A4/D3-D7   ;
  418.     UNLK A6                     ;
  419.     MOVEA.L (SP)+,A0            ;
  420.     ADD.L #4,SP                 ;
  421.     JMP (A0)                    ;
  422.                     
  423. END